﻿// GNSSListDlg.cpp: 实现文件
//

#include "pch.h"
#include "JointSerialTest.h"
#include "GNSSListDlg.h"
#include "afxdialogex.h"
#include "Devices.h"


// GNSSListDlg 对话框

IMPLEMENT_DYNAMIC(GNSSListDlg, CDialogEx)

GNSSListDlg::GNSSListDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_GNSSLIST, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

GNSSListDlg::~GNSSListDlg()
{
}

void GNSSListDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_GLIST, datalist);
}

BOOL GNSSListDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	SetIcon(m_hIcon, TRUE);			// 设置大图标

	for (size_t k = 0; k < 10; k++)
	{
		datalist.InsertColumn(k, titles[k], LVCFMT_CENTER, width[k]);
	}
	return 0;
}

BEGIN_MESSAGE_MAP(GNSSListDlg, CDialogEx)
	ON_MESSAGE(LISTMSG_GETGNSS, addData)
END_MESSAGE_MAP()

// GNSSListDlg 消息处理程序
LRESULT GNSSListDlg::addData(WPARAM wParam, LPARAM lParam)
{
	GPGGADATA* posdata = (GPGGADATA*)wParam;
	BESTVELDATA* veldata = (BESTVELDATA*)lParam;
	CString nextContent;
	INT idx = 0;
	nextRowNUm = datalist.InsertItem(nextRowNUm, _T(""));
	nextContent.Format(_T("%d"), veldata->ph.second);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), veldata->vel_h);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), veldata->heading);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), veldata->vel_v);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), posdata->Lat);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), posdata->Lng);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), posdata->Alt);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), posdata->Herr);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%d"), posdata->SatNum);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), posdata->HDOP);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	if (nextRowNUm++ > 20)
	{
		nextRowNUm = 0;
		datalist.DeleteAllItems();
	}
	return LRESULT();
}

